#ifndef __CTRL_ENCODER_H__
#define __CTRL_ENCODER_H__

#include "all.h"

/*
    For control module, Encoder function:
    1 Select function
        0:  reserved    (Nothing to do)

        1:  StartPoint                  - Need RC On and Ch6 control
        2:  StartPoint To EndPoint      - Need RC On and Ch6 control
        3:  StartPoint LeftDown LeftUp  - Need RC On and Ch6 control

        4:  StartPoint                  - Need RC Always Off
        5:  StartPoint To EndPoint      - Need RC Always Off
        6:  StartPoint LeftDown LeftUp  - Need RC Always Off

        7:
        8:
        9:
        A:
        B:
        C:
        D:
        E:
        F:
*/

#define ENCODER_VALUE_RAW   (       (!(PORT3.PIDR.BIT.B2) << 2)     \
                                |   (!(PORT3.PIDR.BIT.B1) << 1)     \
                                |    !(PORT3.PIDR.BIT.B0)        )

#define ENCODER_VALUE       ((ENCODER_VALUE_RAW) & 0x000F)

extern uint16 EncoderPowerOn_Value;

extern void Update_Encoder_Value(void);             // 更新编码器当前值
extern void Update_Encoder_PowerOn_Value(void);     // 更新编码器上电值
extern uint16 Get_Encoder_Value(void);              // 获取编码器当前值
extern uint16 Get_Encoder_PowerOn_Value(void);      // 获取编码器上电初始值

#endif  // __CTRL_ENCODER_H__

